<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$id = UV::readInt(strip_tags($route->GET("id")));
$type = UV::readMQ(strip_tags($route->GET("type")));
if (isset($_COOKIE['_sess']) && $_COOKIE['_sess'] != ""){
	$sess_id = $_COOKIE['_sess'];
} else {
	$sess_id = md5(randString().$_SERVER['REMOTE_ADDR']);
	setcookie("_sess",$sess_id,strtotime("01.01.2015"),"/");
}
$user_ip = $_SERVER['REMOTE_ADDR'];

$user_vote = $db->getCell("select count(`like_id`) from `likes` where (`user_ip` = '$user_ip' and `sess_id` = '$sess_id') and `vote_id` = '$id'");
if ($user_vote == 0)
	$db->sendQuery("insert into `likes` values(NULL,'$id','$type','$user_ip','$sess_id')");

echo $db->getCell("select count(`mean`) from `likes` where `vote_id` = '$id' and `mean` = '$type'");

?>